package com.AAL.Action;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.AAL.DAO.ContractDetailDAO;
import com.AAL.DAO.PurchaseContractDAO;
import com.AAL.DAO.StatusOfContractDAO;
import com.AAL.DAO.TypeOfAutoDAO;
import com.AAL.DAO.TypesOfWheelDAO;


import com.AAL.Model.PurchaseContract;
import com.AAL.Model.ContractDetail;
import com.AAL.Model.TypesOfWheel;
import com.AAL.Model.TypeOfAuto;


import com.AAL.Model.StatusOfContract;
import com.AAL.Model.Employee;



@SuppressWarnings("serial")
public class CoodinatorAction extends ActionSupport implements SessionAware {
	private Map<String, Object> session;
	private List<PurchaseContract> listcontract;
	private PurchaseContractDAO lnkcontractDAO;
	private StatusOfContractDAO lnkStatusContract;
	private ContractDetailDAO lnkContractDetailDAO;
	private TypeOfAutoDAO lnkTypeOfAuto;
	private TypesOfWheelDAO lnkTypeOfWheel;
	private List<StatusOfContract> listStatusContract;
	private List<TypeOfAuto> lstTypeOfAuto;
	private List<TypesOfWheel> lstTypeOfWheel;
	private int StatusID;
	
	private PurchaseContract contract = new PurchaseContract();
	
	private List<ContractDetail> lstContractDetail;
	
	private StatusOfContract status = new StatusOfContract();
	
	private Employee employee=new Employee();

	public CoodinatorAction() {
		this.setLnkcontrachDAO(new PurchaseContractDAO());
		this.setLnkStatusContract(new StatusOfContractDAO());
		this.lnkContractDetailDAO = new ContractDetailDAO();
	}
	public String addNewPurchaseContract() {
		try {
		} catch (Exception e) {
			return ERROR;
		}
		return SUCCESS;
	}

	public String getPurchaseContract() {
		HttpServletRequest request = (HttpServletRequest) ActionContext
		.getContext().get(ServletActionContext.HTTP_REQUEST);
		try {
		System.out.print("id"+request.getParameter("id"));
		this.contract=	lnkcontractDAO.getPurchaseContract(Integer.parseInt(request.getParameter("id")));
		this.lstContractDetail = lnkContractDetailDAO.getLstContractDetailsByContract(this.contract);
		} catch (Exception e) {
			return ERROR;
		}
		return SUCCESS;
	}

	public String getLstPurchaseContract() {
		try {
			this.listcontract=lnkcontractDAO.getLstAllPurchaseContract();
			this.listStatusContract=lnkStatusContract.getAllStatusOfContracts();
		}catch (Exception e) {
			addActionError("Loi:" + e.getMessage());
			return ERROR;
		}
		return SUCCESS;
	}

	public String deletePurchaseContract() {
		HttpServletRequest request = (HttpServletRequest) ActionContext
		.getContext().get(ServletActionContext.HTTP_REQUEST);
		try {
			lnkcontractDAO.deletePurchaseContract(Integer.parseInt(request.getParameter("id")));
		} catch (Exception e) {
			return ERROR;
		}
		return SUCCESS;
	}

	public String preEditAndAddNewPurchaseContract() {
		return SUCCESS;
	}
	

	@Override
	public void setSession(Map<String, Object> arg0) {
		// TODO Auto-generated method stub

	}
	public Map<String, Object> getSession() {
		return session;
	}
	public void setListcontract(List<PurchaseContract> listcontract) {
		this.listcontract = listcontract;
	}
	public List<PurchaseContract> getListcontract() {
		return listcontract;
	}
	public void setLnkcontrachDAO(PurchaseContractDAO lnkcontractDAO) {
		this.lnkcontractDAO = lnkcontractDAO;
	}
	public PurchaseContractDAO getLnkcontrachDAO() {
		return lnkcontractDAO;
	}
	public void setContract(PurchaseContract contract) {
		this.contract = contract;
	}
	public PurchaseContract getContract() {
		return contract;
	}
	public void setLnkStatusContract(StatusOfContractDAO lnkStatusContract) {
		this.lnkStatusContract = lnkStatusContract;
	}
	public StatusOfContractDAO getLnkStatusContract() {
		return lnkStatusContract;
	}
	public void setLnkTypeOfAuto(TypeOfAutoDAO lnkTypeOfAuto) {
		this.lnkTypeOfAuto = lnkTypeOfAuto;
	}
	public TypeOfAutoDAO getLnkTypeOfAuto() {
		return lnkTypeOfAuto;
	}
	public void setListStatusContract(List<StatusOfContract> listStatusContract) {
		this.listStatusContract = listStatusContract;
	}
	public List<StatusOfContract> getListStatusContract() {
		return listStatusContract;
	}
	public void setLstTypeOfWheel(List<TypesOfWheel> lstTypeOfWheel) {
		this.lstTypeOfWheel = lstTypeOfWheel;
	}
	public List<TypesOfWheel> getLstTypeOfWheel() {
		return lstTypeOfWheel;
	}
	public void setStatusID(int statusID) {
		StatusID = statusID;
	}
	public int getStatusID() {
		return StatusID;
	}
	public void setStatus(StatusOfContract status) {
		this.status = status;
	}
	public StatusOfContract getStatus() {
		return status;
	}
	public void setLnkTypeOfWheel(TypesOfWheelDAO lnkTypeOfWheel) {
		this.lnkTypeOfWheel = lnkTypeOfWheel;
	}
	public TypesOfWheelDAO getLnkTypeOfWheel() {
		return lnkTypeOfWheel;
	}
	public void setLstTypeOfAuto(List<TypeOfAuto> lstTypeOfAuto) {
		this.lstTypeOfAuto = lstTypeOfAuto;
	}
	public List<TypeOfAuto> getLstTypeOfAuto() {
		return lstTypeOfAuto;
	}
	
	public void setEmployee(Employee employee) {
		this.employee = employee;
	}
	public Employee getEmployee() {
		return employee;
	}
	public List<ContractDetail> getLstContractDetail() {
		return lstContractDetail;
	}
	public void setLstContractDetail(List<ContractDetail> lstContractDetail) {
		this.lstContractDetail = lstContractDetail;
	}
}
